/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.iprojectmanager.views;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.iprojectmanager.managers.*;
import com.iprojectmanager.entities.*;
/**
 *
 * @author Enrique
 */
public class VistaEvaluarMaterial extends Vista{
    
    public void mainView(PrintWriter out, LiderProyecto lid, String user){
        out.println(Utilities.getDocType());
        out.println("<HTML>" + Utilities.getHead("Enviar Avance"));
        out.println("<div id=\"container\">");
        out.println(Utilities.getIntro("Enviar Avance",lid));
        String content = "<div id=\"pageContent\">"+
               "<div id=\"selection1\">"+"</div>"+
               this.getFormActivities(lid,user) +
               Utilities.getFooter() + "</div>";
        out.println(content);
        out.println(Utilities.getMenu());
        out.println("</div> <!-- fin container --> </BODY></HTML>");
    }
    
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        String usuario = request.getParameter("usuario");
        PrintWriter out = response.getWriter();
        HttpSession user = request.getSession();
        LiderProyecto lider = (LiderProyecto)user.getAttribute("user");
        mainView(out,lider,usuario);
    }
    
    public String getFormActivities(LiderProyecto lider, String user){
        //ActivitiesManager actividad = new ActivitiesManager();
        Proyecto proyecto = lider.getProyecto();
        String avance = "";
        String opciones="<h3>"+
                            "<span>Aceptar/rechazar avance</span>"+
                        "</h3>"+
                        "<p class=\"p1\">"+
                        "<span>"+
                        "<form action=\"ActivityControl\" method=\"GET\">"+
                        "<Table border=\"1\" cellspacing=\"1\">"+
                        "<tr>"+
                            "<th>"+
                                "<b>Aceptar</b>"+
                            "</th>"+
                            "<th>"+
                                "<b>Actividad</b>"+
                            "</th>"+
                            "<th>"+
                                "<b>Archivo</b>"+
                            "</th>"+
                            "<th>"+
                                "<b>Integrante</b>"+
                            "</th>"+
                        "</tr>";
        for(Actividad lista : proyecto.getActividades())
        {
            if(lista.getResponsable() != null && lista.getResponsable().getId().toString().compareToIgnoreCase(user)==0){
                if(lista.getAvance()==null){
                    avance = "Ninguno";
                }else{
                    avance = "<a href=\""+getServletContext().getRealPath("/")+proyecto.getNombre()+"\\"+lista.getNombre()+"\\"+lista.getAvance()+"\">"+lista.getAvance()+"</a>";
                }
                opciones += "<tr>"+
                            "<td>"+
                                "<input type=\"checkbox\" value=\""+lista.getId()+"\" name=\"actividades\">"+
                            "</td>"+
                            "<td>"+lista.getNombre()+"</td>"+"" +
                            "<td>"+
                                avance+
                            "</td>"+
                                "<td>"+lista.getResponsable().getNombre()+" "+lista.getResponsable().getApellidoPaterno()+" "+lista.getResponsable().getApellidoMaterno()+"</td>"+
                            "</tr>";
            }
        }
        opciones += "</Table><br> </br><input type=\"submit\" value=\"Aceptar\" name=\"Aceptar\">"+
                "<input type=\"reset\" value=\"Reset\" name=\"reset\">"+
                "</form></span></p>";
        return opciones;
    }
}
